import unittest, ddt
from demoForJenkins.Flow.login import Login


@ddt.ddt
class TestLogin(unittest.TestCase):
    '''登录模块'''

    def setUp(self):
        # 准备测试环境或数据
        print("==================Start==================")
        self.l = Login()
        self.url = 'http://localhost/agileone/index.php/common/login'

    # @ddt.ddt(['admin', 'admin', 'successful'], ['admin', ' ', 'password_invalid'])
    # @ddt.unpack
    # def testUserPwdValid(self, username, pwd, expectResult):
    #     print(username, pwd, expectResult)
    #     response = self.l.login(self.url, username, pwd)
    #     self.assertEqual(response, expectResult)

    def testUserPwdValid(self):
        response = self.l.login(self.url, 'admin', 'admin')
        self.assertEqual(response, 'successful')

    def testUserInvalid(self):
        response = self.l.login(self.url, 'admin1234', 'admin')
        self.assertEqual(response, 'user_invalid')

    def testPwdInvalid(self):
        response = self.l.login(self.url, 'admin', 'admin17323232')
        self.assertEqual(response, 'password_invalid')

    def testUserNull(self):
        response = self.l.login(self.url, '', 'admin')
        self.assertEqual(response, 'user_invalid')

    def testPwdNull(self):
        response = self.l.login(self.url, 'admin', '')
        self.assertEqual(response, 'password_invalid')

    def tearDown(self):
        # 清理数据, 还原测试环境
        print("==================End==================")


if __name__ == '__main__':
    unittest.main()
